/*
 * @Author: szx
 * @Date: 2022-01-28 14:53:36
 * @LastEditTime: 2022-01-28 15:52:15
 * @Description:
 * @FilePath: \leetcode\200-299\290\290.js
 */
/**
 * @param {string} pattern
 * @param {string} s
 * @return {boolean}
 */
var wordPattern = function (pattern, s) {
    const arr = s.split(' ');
    if (arr.length != pattern.length) return false;
    const parr = new Array(26).fill(-1);
    const map = new Map();
    for (let i = 0; i < arr.length; i++) {
        const index = pattern.charCodeAt(i) - 97;
        if (map.get(arr[i]) == undefined && parr[index] == -1) {
            parr[index] = arr[i];
            map.set(arr[i], index);
        } else if (parr[index] !== arr[i] || map.get(arr[i]) !== index) {
            // console.log(index)
            // console.log(parr[index]);
            // console.log(map.get(arr[i]));
            return false;
        }
    }
    return true;
};
console.log(wordPattern('abba', 'dog cat cat dog'));
